<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .carousel {
            margin-top: 50px;
            margin-left: 200px;
            width: 800px;
            height: 350px;
            /* position: relative; */
        }

        .cal-list {
            width: 800px;
            height: 350px;
            position: relative;
            /* 超出不显示 */
            overflow: hidden;
        }

        .pic {
            width: 800px;
            height: 350px;
        }

        .itme {
            float: left;
        }

        .viewpage {
            position: absolute;
            left: 0;
            top: 0;
            width: 700%;
            height: 350px;
        }
    </style>
</head>

<body>
    <div class="carousel">
        <!-- 所有图片,图片列表 -->
        <div class="cal-list">
            <ul class="viewpage">
                <li class="itme"><img src="./img/one.png" class="pic"></li>
                <li class="itme"><img src="./img/two.png" class="pic"></li>
                <li class="itme"><img src="./img/three.png" class="pic"></li>
                <li class="itme"><img src="./img/four.png" class="pic"></li>
                <li class="itme"><img src="./img/five.png" class="pic"></li>
                <li class="itme"><img src="./img/six.png" class="pic"></li>
                <li class="itme"><img src="./img/one.png" class="pic"></li>
            </ul>
        </div>
    </div>
</body>
<script src="./js/animationutils.js"></script>
<script>
    var viewpage = document.getElementsByClassName('viewpage')[0];
    var itmes = document.getElementsByClassName('itme');
    var calList = document.getElementsByClassName('cal-list')[0];
    var index = 0;

    //自动轮播
    function autoplay() {
        inteID= setInterval(function () {
            index++;
            if (index >= itmes.length) {
                viewpage.style.left = '0px';
                index = 1;
            }

            var target = -800 * index;
            moveAnimation(viewpage, target);
        }, 2000)
    }
    autoplay();

    //悬停暂停.离开暂停
    calList.onmouseover=function(){
        clearInterval(inteID);
    }
    calList.onmouseleave=function(){
        autoplay();
    }
</script>

</html>